from selenium.webdriver.common.by import By
from page.base_page import BasePage
from utils import DriverTools


class LoginPage(BasePage):

    def __init__(self):
        self.driver = DriverTools.get_driver()
        self.username_input_loc = By.ID, "username"
        self.password_input_loc = By.ID, "password"
        self.verify_code_input_loc = By.ID, "verify_code"
        self.login_btn_loc = By.CSS_SELECTOR, "[name='sbtbutton']"
        self.alert_text_loc = By.XPATH, "//*[@class='layui-layer-content layui-layer-padding']"

    def login(self, username, password, verify_code):
        """登录"""
        self.input(self.username_input_loc, username)
        self.input(self.password_input_loc, password)
        self.input(self.verify_code_input_loc, verify_code)
        self.click(self.login_btn_loc)

    def get_text(self):
        """获取弹出框文本"""
        #
        return self.get_alert_text(self.alert_text_loc)